import { _decorator, Color, Component, Sprite, Tween, tween, Vec2, Vec3 } from 'cc';
import { Game } from '../Game';
import { EffectManager } from './EffectManager';
const { ccclass } = _decorator;

@ccclass('TxDian')
export class TxDian extends Component {

    init_1(pos: any) {
        Tween.stopAllByTarget(this.node);
        var i_num_1 = Math.floor(Math.random() * 256)
        var i_num_2 = Math.floor(Math.random() * 256)
        var i_num_3 = Math.floor(Math.random() * 256)
        if (Math.random() < 0.6) {
            i_num_1 = 255
            i_num_2 = 255
            i_num_3 = 255
        }
        this.node.getComponent(Sprite).color = new Color(i_num_1, i_num_2, i_num_3);
        var x_min = pos.x - 150
        var y_min = pos.y - 50
        var pos_begin = new Vec3(x_min + Math.random() * 300, y_min + Math.random() * 250)
        this.node.setPosition(pos_begin)
        const randomScale = 0.5 + Math.random() * 0.5;
        this.node.setScale(randomScale, randomScale, 1);
        const duration = 0.3 + Math.random() * 100 * 0.005;
        const moveTween = new Tween(this.node)
            .to(duration, { position: pos })
            .call(() => {
                EffectManager.instance.onDianKilled(this.node);
            })
            .start();
    }

    init_2(pos: any) {
        Tween.stopAllByTarget(this.node);
        var i_num_1 = Math.floor(Math.random() * 256)
        var i_num_2 = Math.floor(Math.random() * 256)
        var i_num_3 = Math.floor(Math.random() * 256)
        if (Math.random() < 0.6) {
            i_num_1 = 255
            i_num_2 = 255
            i_num_3 = 255
        }
        this.node.getComponent(Sprite).color = new Color(i_num_1, i_num_2, i_num_3);
        var x_min = pos.x - 120
        var pos_end = new Vec3(x_min + Math.random() * 240, pos.y + Math.random() * 150)
        this.node.setPosition(pos)
        const randomScale = 0.3 + Math.random() * 0.3
        this.node.setScale(randomScale, randomScale, 1);
        const duration = 0.3 + Math.random() * 100 * 0.002;
        const moveTween = new Tween(this.node)
            .to(duration, { position: pos })
            .call(() => {
                // 执行回调逻辑
                EffectManager.instance.onDianKilled(this.node);
            })
            .start();
    }
}
